package abstractClass.no1;

import java.util.InputMismatchException;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Employee employee;
		int choice;
		Scanner scanner=new Scanner(System.in);
		while (true){
			try {
				System.out.println("请选择职务");
				System.out.println("1.销售员");
				System.out.println("2.工程师");
				System.out.println("0.退出");
				choice=scanner.nextInt();

				switch (choice){
					case 1:
						System.out.print("请输入职工姓名和工作时长");
						employee=new Salesperson(scanner.next(), scanner.nextInt());
						break;
					case 2:
						System.out.print("请输入职工姓名和工作时长");
						employee=new Engineer(scanner.next(),scanner.nextInt());
						break;
					case 0:
						System.out.println("欢迎下次使用");
						return;
					default:
						System.out.println("选择无效，请重试");
						continue;
				}
				System.out.println("员工"+employee.name
						+"\t本月工资为"+employee.calculateSalary()+"元");
			}
			catch (InputMismatchException inputMismatchException){
				System.out.println("选择无效，请重试");
			}
		}
	}
}
abstract class Employee {
	String name;

	Employee(String name) {
		this.name = name;
	}

	abstract double calculateSalary();
}

class Salesperson extends Employee {

	final double baseSalary = 2000;
	final double commissionRate = 0.1;
	double salesAmount;

	Salesperson(String name, double salesAmount) {
		super(name);
		this.salesAmount = salesAmount;
	}

	@Override
	double calculateSalary() {
		return baseSalary + salesAmount * commissionRate;
	}
}

class Engineer extends Employee {
	final double hourlyWage = 20;
	int hoursWorked;
	Engineer(String name, int hoursWorked) {
		super(name);
		this.hoursWorked = hoursWorked;
	}

	@Override
	double calculateSalary() {

		return hourlyWage * hoursWorked;
	}
}